#!/usr/bin/env python
# coding=utf-8
"""
# @Created on : 2016/04/22 14:45
# @Author     : ldf (ldf@eehello.com)
# @Link       : http://www.eehello.com
# @Version    : 
# 本程序在python2.7下测试通过
"""

import socket
import sys
import os

ip_port = ('127.0.0.1', 9999)
sk = socket.socket()
sk.connect(ip_port)

while 1:
    input = raw_input('path: ')
    cmd,path = input.split('|')
    file_name = os.path.basename(path)
    file_size = os.stat(path).st_size
    sk.send(cmd+"|"+file_name+"|"+str(file_size))
    send_size = 0
    f = open(path, 'rb')
    flag = 1
    while flag:
        if send_size + 1024 > file_size:
            data = f.read(file_size - send_size)
            flag = 0
        else:
            data = f.read(1024)
            send_size += 1024
        sk.send(data)
    f.close()

sk.close()
